<?php
if (isset($_POST['op']) &&  !empty($_POST['op']) ){
    include 'load.php';
    $openid=$_POST['op'];
    $name=addslashes($_POST['n']);
    $avatar=addslashes($_POST['a']);
    $sex=addslashes($_POST['sex']);
    $province=addslashes($_POST['p']);
    $city=addslashes($_POST['city']);
    $hashui=addslashes($_POST['hashui']);
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    
    $query=$mysqli->query("SELECT id FROM users where openid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
    }else{
        $mysqli->query("insert into users(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."')  ");
    }
    
    $mysqli->query("update users set nickname='".$name."',avatar='".$avatar."',sex='".$sex."',province='".$province."', city='".$city."' where openid='".$openid."'  ");
    $mysqli->query("update users set name='".base64_encode($_POST['n'])."' where openid='".$openid."'  ");

    if('not' == $hashui){
        $query=$mysqli->query("SELECT memberno,phone FROM uinfo where openid='".$openid."' limit 0,1 ");
        if($query->num_rows>0){
            $getUinfo=$query->fetch_array();
    
            if (empty($getUinfo['memberno']) &&  !empty($getUinfo['phone'])){
                
                echo json_encode(array('msg'=>'goreg'));
                $mysqli->close();
                exit;
            }
        }
    }
    
    
    $mysqli->close();
    echo json_encode(array('msg'=>1));
}